<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap/boostrap-hover-dropdown.js"></script>

<script>
    //ajax - 获取种类信息
    $(function () {
        $.get("${pageContext.request.contextPath}/category", {"method": "categoryList"},
            function (data) {
                $(data).each(function (index, obj) {
                    if (obj.categoryId == '${requestScope.categoryId}') {
                        $("#categoryUl").append("<li class='active'><a href='${pageContext.request.contextPath}/article?method=articleList&categoryId=" + obj.categoryId + "'>" + obj.categoryName + "</a></li>");
                    } else {
                        $("#categoryUl").append("<li><a href='${pageContext.request.contextPath}/article?method=articleList&categoryId=" + obj.categoryId + "'>" + obj.categoryName + "</a></li>");
                    }
                })
            },
            "json");
    })
</script>


<div class="container-fluid">
    <div class="col-md-4">
        <img src="${pageContext.request.contextPath}/images/logo.png"/>
    </div>
    <div class="col-md-4"></div>
    <div class="col-md-4" style="padding-top: 20px; text-align: right;">
        <ol class="list-inline">
            <c:choose>
                <c:when test="${empty sessionScope.user}">
                    <li><a href="User?method=log">登录</a></li>
                    <li><a href="User?method=register">注册</a></li>
                </c:when>
                <c:otherwise>
                    <li><a href="User?method=personal&update=true&userId=${sessionScope.user.getUserId()}">个人中心</a></li>
                    <li><a href="User?method=logout">注销</a></li>
                    <li><a href="article?method=writeArticle">写贴</a></li>
                </c:otherwise>
            </c:choose>
        </ol>
    </div>
</div>

<div class="container-fluid">
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed"
                        data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
                        aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span
                        class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="${pageContext.request.contextPath}/Forum">首页</a>
            </div>

            <div class="collapse navbar-collapse"
                 id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav" id="categoryUl">
                </ul>

                <form class="navbar-form navbar-right" action="${pageContext.request.contextPath}/article"
                      method="post">
                    <input type="hidden" name="method" value="articleQuery">&nbsp;
                    <div class="form-group">
                        <input type="text" class="form-control" name="inputName" placeholder="输入搜索贴名">
                    </div>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>

            </div>
        </div>
    </nav>
</div>